<?php

class Create extends CI_Controller{
	
	public function petition(){
		get_instance()->load->model('petitions/Category');
		$data['categories_options'] = get_instance()->Category->getAllCategories();
		$data['content'] = get_instance()->load->view('content/create-petition-content',$data,TRUE);

		get_instance()->load->view('templates/layout', $data);

	}

	public function submit(){
		$title = $_POST['input-petition-title'];
		$category = isset($_POST['input-petition-category']) ? is_int((int) $_POST['input-petition-category']) ? (int) $_POST['input-petition-category'] : NULL : null;
		$text = $_POST['input-petition-text'];
		get_instance()->load->model('petitions/Petition');

		
		$errors = get_instance()->Petition->submit_petition($title,$category,$text);
		if (!is_null($errors)) foreach($errors as $e){
			echo $e . '<br>';
		}
		
	}

}